package com.fye.tabletreewidget.client;

import com.fye.tabletreewidget.client.listener.TableTreeListener;
import com.google.gwt.user.client.ui.Composite;

public class TableTreeTest extends Composite implements TableTreeListener
{
	private TableTree myTableTree;
	
	TableTreeItem itemxx;
	
	public TableTreeTest()
	{
		
		myTableTree = new TableTree();
		
		initListener();
		
		itemxx = myTableTree.newTreeItem( "itemxx" );
		
		initTableTreeData();
		
		initWidget( myTableTree );
	}


	private void initListener()
	{
		myTableTree.addTableTreeListener( this );
	}


	private void initTableTreeData()
	{
		TableTreeItem item1;
		TableTreeItem item2;
		TableTreeItem item3;
		TableTreeItem item11;
		TableTreeItem item12;
		TableTreeItem item13;
		
		TableTreeItem item31;
		TableTreeItem item32;
		TableTreeItem item33;
		
		TableTreeItem item311;
		TableTreeItem item3111;
		TableTreeItem item31111;
		
		itemxx = myTableTree.newTreeItem( "itemxx" );
		
		item1 = myTableTree.newTreeItem( "item1" );
		item2 = myTableTree.newTreeItem( "item2" );
		item3 = myTableTree.newTreeItem( "item3" );
		item11 = myTableTree.newTreeItem( "item11" );
		item12 = myTableTree.newTreeItem( "item12" );
		item13 = myTableTree.newTreeItem( "item13" );
		
		
		item31 = myTableTree.newTreeItem( "item31" );
		item32 = myTableTree.newTreeItem( "item32" );
		item33 = myTableTree.newTreeItem( "item33" );
		
		item311 = myTableTree.newTreeItem( "item311" );
		item3111 = myTableTree.newTreeItem( "item3111" );
		item31111 = myTableTree.newTreeItem( "item31111" );
		
		item1.addItem( item11 );
		item1.addItem( item12 );
		item1.addItem( item13 );
		
		item3.addItem( item31 );
		item3.addItem( item32 );
		item3.addItem( item33 );
		
		item31.addItem( item311 );
		item311.addItem( item3111 );
		item3111.addItem( item31111 );
		
		myTableTree.addRootTreeItem( item1 );
		myTableTree.addRootTreeItem( item2 );
		myTableTree.addRootTreeItem( item3 );
	}


	public void onTableTreeClicked(TableTreeItem treeItem)
	{
		TableTreeItem tmpItem;
		tmpItem = myTableTree.newTreeItem( "tmpItem" );
		treeItem.removeAllItems();
		treeItem.addItem( tmpItem );
	}


	public void onTableTreeStateChanged(TableTreeItem treeItem)
	{
//		TableTreeItem tmpItem;
//		tmpItem = myTableTree.newTreeItem( "tmpItem" );
//		treeItem.removeAllItems();
//		treeItem.addItem( tmpItem );
//		Window.alert("onChanged");
		
	}
}
